package v1

import (
	"gin-vue-admin/global"
	"gin-vue-admin/model"
	"gin-vue-admin/model/request"
	"gin-vue-admin/model/response"
	"gin-vue-admin/service"

	"github.com/gin-gonic/gin"
	"go.uber.org/zap"
)

// CreateMindScale 创建MindScale
// @Tags MindScale
// @Summary 创建MindScale
// @Security ApiKeyAuth
// @accept application/json
// @Produce application/json
// @Param data body model.MindScale true "创建MindScale"
// @Success 200 {string} string "{"success":true,"data":{},"msg":"获取成功"}"
// @Router /MindScale/createMindScale [post]
func CreateMindScale(c *gin.Context) {
	var MindScale model.MindScale
	_ = c.ShouldBindJSON(&MindScale)
	if err := service.CreateMindScale(MindScale); err != nil {
		global.GVA_LOG.Error("创建失败!", zap.Any("err", err))
		response.FailWithMessage("创建失败", c)
	} else {
		response.OkWithMessage("创建成功", c)
	}
}

// DeleteMindScale 删除MindScale
// @Tags MindScale
// @Summary 删除MindScale
// @Security ApiKeyAuth
// @accept application/json
// @Produce application/json
// @Param data body model.MindScale true "删除MindScale"
// @Success 200 {string} string "{"success":true,"data":{},"msg":"删除成功"}"
// @Router /MindScale/deleteMindScale [delete]
func DeleteMindScale(c *gin.Context) {
	var MindScale model.MindScale
	_ = c.ShouldBindJSON(&MindScale)
	if err := service.DeleteMindScale(MindScale); err != nil {
		global.GVA_LOG.Error("删除失败!", zap.Any("err", err))
		response.FailWithMessage("删除失败", c)
	} else {
		response.OkWithMessage("删除成功", c)
	}
}

// DeleteMindScaleByIds 批量删除MindScale
// @Tags MindScale
// @Summary 批量删除MindScale
// @Security ApiKeyAuth
// @accept application/json
// @Produce application/json
// @Param data body request.IdsReq true "批量删除MindScale"
// @Success 200 {string} string "{"success":true,"data":{},"msg":"批量删除成功"}"
// @Router /MindScale/deleteMindScaleByIds [delete]
func DeleteMindScaleByIds(c *gin.Context) {
	var IDS request.IdsReq
	_ = c.ShouldBindJSON(&IDS)
	if err := service.DeleteMindScaleByIds(IDS); err != nil {
		global.GVA_LOG.Error("批量删除失败!", zap.Any("err", err))
		response.FailWithMessage("批量删除失败", c)
	} else {
		response.OkWithMessage("批量删除成功", c)
	}
}

// UpdateMindScale 更新MindScale
// @Tags MindScale
// @Summary 更新MindScale
// @Security ApiKeyAuth
// @accept application/json
// @Produce application/json
// @Param data body model.MindScale true "更新MindScale"
// @Success 200 {string} string "{"success":true,"data":{},"msg":"更新成功"}"
// @Router /MindScale/updateMindScale [put]
func UpdateMindScale(c *gin.Context) {
	var MindScale model.MindScale
	_ = c.ShouldBindJSON(&MindScale)
	if err := service.UpdateMindScale(MindScale); err != nil {
		global.GVA_LOG.Error("更新失败!", zap.Any("err", err))
		response.FailWithMessage("更新失败", c)
	} else {
		response.OkWithMessage("更新成功", c)
	}
}

// FindMindScale 用id查询MindScale
// @Tags MindScale
// @Summary 用id查询MindScale
// @Security ApiKeyAuth
// @accept application/json
// @Produce application/json
// @Param data body model.MindScale true "用id查询MindScale"
// @Success 200 {string} string "{"success":true,"data":{},"msg":"查询成功"}"
// @Router /MindScale/findMindScale [get]
func FindMindScale(c *gin.Context) {
	var MindScale model.MindScale
	_ = c.ShouldBindQuery(&MindScale)
	if err, reMindScale := service.GetMindScale(MindScale.ID); err != nil {
		global.GVA_LOG.Error("查询失败!", zap.Any("err", err))
		response.FailWithMessage("查询失败", c)
	} else {
		response.OkWithData(reMindScale, c)
	}
}

// GetMindScaleList 分页获取MindScale列表
// @Tags MindScale
// @Summary 分页获取MindScale列表
// @Security ApiKeyAuth
// @accept application/json
// @Produce application/json
// @Param data body request.MindScaleSearch true "分页获取MindScale列表"
// @Success 200 {string} string "{"success":true,"data":{},"msg":"获取成功"}"
// @Router /MindScale/getMindScaleList [get]
func GetMindScaleList(c *gin.Context) {
	var pageInfo request.MindScaleSearch
	_ = c.ShouldBindQuery(&pageInfo)
	if err, list, total := service.GetMindScaleInfoList(pageInfo); err != nil {
		global.GVA_LOG.Error("获取失败!", zap.Any("err", err))
		response.FailWithMessage("获取失败", c)
	} else {
		response.OkWithDetailed(response.PageResult{
			List:     list,
			Total:    total,
			Page:     pageInfo.Page,
			PageSize: pageInfo.PageSize,
		}, "获取成功", c)
	}
}
